/**
 * Created by thomas on 2017/12/6.
 */

var current_h= document.body.clientHeight;
var current_w = document.body.clientWidth;

var game = new Phaser.Game(current_w, current_h, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });

function preload() {

    game.load.spritesheet('spinner', './img/4随风而遇-发随缘卡-选择信封_05.png', 32, 32);

}

var sprites;
function listener() {
    console.log("listener__________")
}
function create() {
    setInterval(function () {
        sprites = game.add.physicsGroup(Phaser.Physics.ARCADE);
        //初始化方块

        var y = game.rnd.integerInRange(0, current_w-100);
        console.log(y);
        var s = sprites.create(y, 0, 'spinner');
        s.animations.add('spin', [0, 1, 2, 3]);
        s.play('spin', 20, true);
        s.body.velocity.set(0,100);
        s.events.onInputDown.add(function () {
            console.log(11111111111);
        }, this);

        sprites.setAll('body.collideWorldBounds', true);
    },1000);
    //  Here we create a group, populate it with sprites, give them all a random velocity
    //  and then check the group against itself for collision
    sprites = game.add.physicsGroup(Phaser.Physics.ARCADE);
    //初始化方块

    var y = game.rnd.integerInRange(0, current_w-100);
    console.log(y);
    var s = sprites.create(y,0,'spinner');
    s.animations.add('spin', [0, 1, 2, 3]);
    s.play('spin', 20, true);
    s.body.velocity.set(0,100);

    sprites.setAll('body.collideWorldBounds', true);
    // sprites.setAll('body.bounce.x', 1);
    // sprites.setAll('body.bounce.y', 1);
}

function update() {

        // var y = game.rnd.integerInRange(100, 700);
        // console.log(y)
        // var s = sprites.create(y, 0, 'spinner');
        // s.animations.add('spin', [0, 1, 2, 3]);
        // s.play('spin', 20, true);
        // s.body.velocity.set(0,100);
        //
        // sprites.setAll('body.collideWorldBounds', true);
    //game.physics.arcade.collide(sprites);
}